package com.klun.Utils;

import java.util.Random;

public class GenUtil {

    /**
     * 生成随机字符串
     * @return
     */
    public static String genetaterString(){
        char[] arrayChar = {'a','b','c','d','e','f','g',
                'h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
        Random r = new Random();
        String result = String.valueOf(
                ""+
                arrayChar[r.nextInt(26)] +
                arrayChar[r.nextInt(26)] +
                arrayChar[r.nextInt(26)] +
                arrayChar[r.nextInt(26)]);
        return result;
    }

    /**
     * 生成 Integer 数组
     * @param length 数组长度
     * @param low 最大值
     * @param high 最小值
     * @return
     */
    public static Integer[] genIntArr(int length, int low, int high){
        Random random = new Random();
        Integer diff = high - low;
        Integer[] arr = new Integer[length];
        for (int i = 0; i < length; i++) {
            arr[i] = random.nextInt(diff) + low;
        }
        return arr;
    }

    /**
     * 生成 Integer 数组 不重复数字
     *
     * @param length 数组长度
     * @param low    最大值
     * @param high   最小值
     * @return
     */
    public static int[] genIntArrDiff(int length, int low, int high) {
        if (high - low < length) return null;
        Random random = new Random();
        Integer diff = high - low;
        int[] arr = new int[length];
        Integer[] falg = new Integer[diff];
        int count = 0;
        do {
            int i = random.nextInt(diff);
            if (falg[i] == null) {
                falg[i] = 1;
                arr[count] = i + low;
                count++;
                if (count == length) {
                    return arr;
                }
            }
        } while (true);
    }


    public static void main(String[] args) {
        GenUtil g = new GenUtil();
    }
}
